﻿using MediatR;
using SlaughterItem.Common.Domains.Check_Ins;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace SlaughterItem.API.Application.Commands.Week02.Check_In
{
    public class CheckInAddHandler : IRequestHandler<CheckInAddCommand, Result>
    {
        IBaseRepository<CheckIn> CheckInRep;

        public CheckInAddHandler(IBaseRepository<CheckIn> checkInRep)
        {
            CheckInRep = checkInRep;
        }
        /// <summary>
        /// 进场登记添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(CheckInAddCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                var list = CheckInRep.Add(new CheckIn()
                {
                    CheckInId = request.CheckInId,
                    CheckInNo = request.CheckInNo,
                    EnterTime = request.EnterTime,
                    GoOutTime = request.GoOutTime,
                    CarNo = request.CarNo,
                    SupplierId = request.SupplierId,
                    SettlementTypeId = request.SettlementTypeId,
                    ApproachNum = request.ApproachNum,
                    QuarantineNo = request.QuarantineNo,
                    OriginAddr = request.OriginAddr,
                    CheckInBatch = request.CheckInBatch,
                    Deliveryman = request.Deliveryman,
                    Phone = request.Phone,
                    IdentityCard = request.IdentityCard,
                    EnterRegistrar = request.EnterRegistrar,
                    GoOutRegistrar = request.GoOutRegistrar,
                    QuarantineImg = request.QuarantineImg,
                    CheckInStateId = request.CheckInStateId,
                    Remark = request.Remark,
                    CheckInIsDel = false
                });

                if (list != null)
                {
                    result.Code = (int)CommonErrorCode.Success;
                    result.Data = null;
                    result.Msg = "查询成功";
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
